﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary> 单个技能按钮对象 </summary>
public class SkillButton : MonoBehaviour
{
    /// <summary> 技能对象 </summary>
    Skill skill;

    /// <summary> 图片组件 </summary>
    Image image;

    bool isOnce;


    public void Awake()
    {
        image = GetComponent<Image>();
    }

    /// <summary> 技能按钮初始化，获取技能图片 </summary>
    /// <param name="skillObj">技能对象</param>
    public void initializeButton(Skill skillObj, GameObject go)
    {
        isOnce = skillObj.once;
        image.sprite = skillObj.sprite;
        skill = skillObj;
        GetComponent<Button>().onClick.AddListener(() =>
        {
            skill.Active(go);
            SkillManager._instance.HideButton(go);

            for (int i = 0; i < SkillManager._instance.skillButtons.Length; i++)
            {
                ////取消button按钮事件的监听
                SkillManager._instance.skillButtons[i].GetComponent<Button>().onClick.RemoveAllListeners();
            }
            if (isOnce)
            {
                SkillManager._instance.Skills.Remove(skill);
            }
        }
       );
    }

}
